<template>
  <div id="app" :class="{none:payStart}">
    <router-view/>
    <vFooter></vFooter>
    <vLogin v-if="$store.state.loginbg" @closeBg="closeBg"></vLogin>
    <vPay v-if="payStart"></vPay>
  </div>
</template>

<script>
import '../static/style/common.css'
import vFooter from '@/components/Footer.vue'
import vPay from '@/components/Pay.vue'
import vLogin from '@/pages/login/index'

import {GetToken} from '@/config/api.js'
import {mapState} from 'vuex'


export default {
  name: 'app',
  components:{
    vFooter,vPay,vLogin
  },
  created:function(){
    if(!this.vCheck()){
      this.getToken()
    }else{
      this.vLogin()
    }


  },
  computed: {
	    ...mapState([
	        'payStart'
	    ]),
	},
  methods:{
    //关闭登录窗口
    closeBg(){
      this.$store.dispatch("closeBg");
    },
    async getToken(){
        let data= await GetToken()
        let token=data.data.access_token
        var arr = token.split('');
        var passToken = "";
        for (var i = 0; i < token.length; i++) {
          passToken += arr[i].charCodeAt()*3;
          passToken += "/";
        }
        var lastToken = passToken.substring(0, passToken.length - 1)
        var d = new Date();
        d.setTime(d.getTime() + (604800000));
        var expires = "expires=" + d.toUTCString();
        document.cookie = "bedtoken" + "=" + lastToken + "; " + expires;
        this.$store.dispatch("tokensync",token);
        window.location.reload();
      }
  	}
  	
}
</script>


